package com.yuke.cloud.service.pmc.controller.frontend;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yuke.cloud.common.core.support.BaseController;
import com.yuke.cloud.common.util.wrapper.WrapMapper;
import com.yuke.cloud.common.util.wrapper.Wrapper;
import com.yuke.cloud.service.pmc.dto.ProdFactoryDto;
import com.yuke.cloud.service.pmc.entity.ProdFactory;
import com.yuke.cloud.service.pmc.service.ProdFactoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by zys on 2018/09/28.
*/
@Api(value = "WEB - ProdFactoryController", tags = "处理ProdFactory相关请求", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RestController
@RequestMapping("/mall/prod/factory")
public class MallProdFactoryController extends BaseController {
    @Resource
    private ProdFactoryService prodFactoryService;

    @GetMapping("/app/introduce/{specId}")
    @ApiOperation(httpMethod = "GET", value = "根据ID获取具体信息")
    public Wrapper<String> detail(@ApiParam(name = "specId", value = "记录id") @PathVariable Long specId) {
        return WrapMapper.ok(prodFactoryService.getIntroduceBySpecId(specId));
    }

    @PostMapping("/app/condition")
    @ApiOperation(httpMethod = "POST", value = "根据ID获取具体信息")
    public Wrapper<PageInfo<ProdFactoryDto>> getListDetailByCondition(@ApiParam(name = "id", value = "记录id") @RequestBody(required = false) ProdFactory prodFactory,
                                                                      @ApiParam(name = "page", value = "分页值", defaultValue = "0") @RequestParam(defaultValue = "0") Integer page,
                                                                      @ApiParam(name = "size", value = "每分页返回的记录数", defaultValue = "0") @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<ProdFactoryDto> list = prodFactoryService.getListDetailByCondition(prodFactory);
        PageInfo pageInfo = new PageInfo(list);
        return WrapMapper.ok(pageInfo);
    }
}
